package com.ykdl.member.views;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.RectF;
/**
 * 
 * 巧妈记账的数据bean
 *
 * @since 1.0
 */
public class DrawArcData
{
	public static final int PAINT_BACKGROUND = 0;
	public static final int PAINT_TOTAL = 1;
	public static final int PAINT_TOTALTEXT = 2;
	public static final int PAINT_LINE = 3;

	// tallyType
	// 吃,喝,玩,学,穿,医,用,其他
	public static final int TALLYTYPE_EAT = 10;
	public static final int TALLYTYPE_DRINK = 11;
	public static final int TALLYTYPE_PLAY = 12;
	public static final int TALLYTYPE_LEARN = 13;
	public static final int TALLYTYPE_TOG = 14;
	public static final int TALLYTYPE_DOCTOR = 15;
	public static final int TALLYTYPE_USE = 16;
	public static final int TALLYTYPE_OTHER = 17;
	public static final int TALLYTYPE_ANQUAN = 19;
	public static final int TALLYTYPE_QITA =20;
	
	
	public static final int TALLYTYPE_DEFAULT = 18;

	private float mWidth;
	private float mHeight;

	private float mCentralX;
	private float mCentralY;

	private String mDefTotal = "总计:";
	private String mNumTotal = "￥0.0";

	private float mArcBigSpace = 30;

//	private int background_id = R.drawable.arcbig_background;
//	private int background_id2 = R.drawable.arcbig_background2;
//	private int total_id = R.drawable.arcsmall_background;

	private int arc_size = 10;
	private float[] startArc;
	private float[] sweepArc;

	private Paint paint;

	private RectF def_rectF;
	
	private int alpha = 255;
	
	private Point []line_start;
	private Point []line_end;
	private Point []text_start;
	public Point[] getText_start() {
		return text_start;
	}
	private String line_text[];
	private  float arc_r=0;

	public String[] getLine_text() {
		return line_text;
	}

	public DrawArcData(float mWidth, float mHeight,float parcsapce)
	{
		this.mWidth = mWidth;
		this.mHeight = mHeight;
		mArcBigSpace=parcsapce;
		mCentralX = this.mWidth / 2;
		mCentralY = this.mHeight / 2;
		arc_r=(mWidth - mArcBigSpace)/2;
		paint = new Paint();
	}

	public float[] getStartArc()
	{
		startArc = new float[arc_size];
		return startArc;
	}
	
	public float[] getOldStart(){
		return startArc;
	}

	public float[] getSweepArc()
	{
		sweepArc = new float[arc_size];
		return sweepArc;
	}

	public Paint getPaint(int paintType)
	{
		paint.reset();
		paint.setAntiAlias(true);
		switch (paintType)
		{
		case PAINT_BACKGROUND:

			break;
		case PAINT_TOTAL:

			break;
		case TALLYTYPE_EAT:
			paint.setARGB(alpha, 80, 191, 203);
			break;
		case TALLYTYPE_DRINK:
			paint.setARGB(alpha, 168, 154, 205);
			break;
		case TALLYTYPE_PLAY:
			paint.setARGB(alpha, 216, 230, 81);
			break;
		case TALLYTYPE_LEARN:
			paint.setARGB(alpha, 236, 132, 155);
			break;
		case TALLYTYPE_TOG:
			paint.setARGB(alpha, 254, 231, 89);
			break;
		case TALLYTYPE_DOCTOR:
			paint.setARGB(alpha, 223, 63, 65);
			break;
		case TALLYTYPE_USE:
			paint.setARGB(alpha, 240, 149, 58);
			break;
		case TALLYTYPE_ANQUAN:
			paint.setARGB(alpha, 125, 215, 249);
			break;
			
		case TALLYTYPE_QITA:
			paint.setARGB(alpha, 142, 244, 161);
			break;
			
		case TALLYTYPE_OTHER:
			paint.setARGB(alpha, 137, 178, 234);
			break;
		case TALLYTYPE_DEFAULT:
			paint.setColor(Color.GRAY);
			paint.setAlpha(alpha);
			break;
		case PAINT_TOTALTEXT:
			paint.setTextSize(24);
			paint.setColor(Color.WHITE);
			break;
		case PAINT_LINE:
			paint.setTextSize(18);
			paint.setColor(Color.BLACK);
			break;
			
		}
		return paint;
	}

	public float[] getArcByIndex(int i)
	{
		float start = startArc[i];
		float sweep = sweepArc[i];
		return new float[]
		{ i + TALLYTYPE_EAT, start, sweep };
	}

	public RectF getArc_Rect()
	{
		if (def_rectF == null)
		{
			float space = mArcBigSpace / 2;
			def_rectF = new RectF(space, space, mWidth - space, mHeight - space);
		}
		return def_rectF;
	}

//	public Rect getTotalRect(String s)
//	{
//		Rect result = null;
//		if ("src".equals(s))
//		{
//			result = new Rect(0, 0, 166, 166);
//		} else if ("dst".equals(s))
//		{
//			float half_length = 166 / 2;
//
//			result = new Rect((int) (mCentralX - half_length + 5),
//					(int) (mCentralY - half_length + 5), (int) (mCentralX
//							+ half_length + 5),
//					(int) (mCentralY + half_length + 5));
//		}
//		return result;
//	}

	public Bitmap getBitmapById(Context context, int id)
	{
		Bitmap bitmap = BitmapFactory
				.decodeResource(context.getResources(), id);
		return bitmap;
	}

//	public int getBackground_id()
//	{
//		return background_id;
//	}
//
//	public void setBackground_id(int background_id)
//	{
//		this.background_id = background_id;
//	}

	public int getArc_size()
	{
		return arc_size;
	}

	public void setArc_size(int arc_size)
	{
		this.arc_size = arc_size;
	}

//	public int getTotal_id()
//	{
//		return total_id;
//	}
//
//	public void setTotal_id(int total_id)
//	{
//		this.total_id = total_id;
//	}

	public String getmDefTotal()
	{
		return mDefTotal;
	}

	public void setmDefTotal(String mDefTotal)
	{
		this.mDefTotal = mDefTotal;
	}

	public String getmNumTotal()
	{
		return mNumTotal;
	}

	public void setmNumTotal(String mNumTotal)
	{
		this.mNumTotal = mNumTotal;
	}

	public float getmCentralX()
	{
		return mCentralX;
	}

	public float getmCentralY()
	{
		return mCentralY;
	}

//	public int getBackground_id2()
//	{
//		return background_id2;
//	}
//
//	public void setBackground_id2(int background_id2)
//	{
//		this.background_id2 = background_id2;
//	}
	

	public void countPoint(float[] start2, float[] sweep2) {
		int leng=start2.length;
		line_start=new Point[leng];
		line_end=new Point[leng];
		line_text=new String[leng];
		text_start=new Point[leng];
		float textwid=getPaint(PAINT_LINE).measureText("99.9%");
		
		
		float[] centerArc=new float[leng];
		float []endArc=new  float[leng];
		for(int i=0;i<leng;i++){
			if(sweep2[i]==0){
				continue;
			}
			endArc[i]=start2[i]+sweep2[i];
			centerArc[i]=start2[i]+sweep2[i]/2;
			line_text[i]=String.format("%.1f", sweep2[i]*100/360)+"%";
		}
		float wid=arc_r;
		double pi=(2*Math.PI)/360;
		int linewid=10;
		for(int i=0;i<leng;i++){
			if(sweep2[i]==0){
				continue;
			}
		
			
          if(centerArc[i]<=90){
        	   
            		  int y=(int)(Math.abs(Math.sin(centerArc[i]*pi))*wid);
                	  int x=(int)(Math.abs(Math.cos(centerArc[i]*pi))*wid);
               
                	  line_start[i]=new Point((int)(x-linewid),(int)(y));
                	  line_end[i]=new Point((int)(x+linewid),(int)(y)); 
                	  text_start[i]= new Point((int)(x+linewid),(int)(y)); 
        	 
          }else if(centerArc[i]<=180){
        	  int y=(int)(Math.abs(Math.sin((180-centerArc[i])*pi))*wid);
        	  int x=(int)(Math.abs(Math.cos((180-centerArc[i])*pi))*wid);
        	  line_start[i]=new Point((int)(-x+linewid),(int)(y));
        	  line_end[i]=new Point((int)(-x-linewid),(int)(y)); 
        	  text_start[i]= new Point((int)(-x-linewid-textwid),(int)(y)); 
        	  
          }else if(centerArc[i]<=270){        	  
        	  int y=(int)(Math.abs(Math.sin(centerArc[i]*pi))*wid);
        	  int x=(int)(Math.abs(Math.cos(centerArc[i]*pi))*wid);
        	  line_start[i]=new Point((int)(-x+linewid),(int)(-y));
        	  line_end[i]=new Point((int)(-x-linewid),(int)(-y));
        	  text_start[i]= new Point((int)(-x-linewid-textwid),(int)(-y)); 
          }else{
        	  int y=(int)(Math.abs(Math.sin((360-centerArc[i])*pi))*wid);
        	  int x=(int)(Math.abs(Math.cos((360-centerArc[i])*pi))*wid);
        	  line_start[i]=new Point((int)(x-linewid),(int)(-y));
        	  line_end[i]=new Point((int)(x+linewid),(int)(-y));
        	  text_start[i]= new Point((int)(x+linewid),(int)(-y));
          }   

		}	
	}
	public Point[] getLinePoint(int i){
		if( line_start[i]!=null&& line_end[i]!=null){
			return new Point[]{line_start[i],line_end[i]};
		}
		return null;
	}
}
